package android.slc.core.ui.fragment.preference;

import android.os.Bundle;
import android.slc.core.ui.delegate.ISupportView;
import android.slc.core.vm.BarVm;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

/**
 * @author slc
 * @date 2023/9/4
 **/
public abstract class BasePreferenceFragment extends EnhancePreferenceFragment implements IPreferenceSupportView {
    protected BarVm mBarVm;
    protected BasePreferenceViewDelegate mViewDelegate;

    @Override
    public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
        onInitViewDelegate(savedInstanceState, rootKey);
    }

    /**
     * 初始化ViewDelegate
     *
     * @param savedInstanceState
     */
    protected void onInitViewDelegate(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
        mViewDelegate = new BasePreferenceViewDelegate(this);
        mViewDelegate.onCreatePreferences(savedInstanceState, rootKey);
    }

    @Override
    public final void onBindView(@Nullable Bundle savedInstanceState) {
        IPreferenceSupportView.super.onBindView(savedInstanceState);
    }


    /**
     * 初始化BarVm
     */
    protected void onInitBarVm() {
        mBarVm = new ViewModelProvider(_mActivity, _mActivity.getDefaultViewModelProviderFactory()).get(BarVm.class);
        mBarVm.syncBarStyle();
    }

    /**
     * 初始化视图之前的回调，详细解析在{@link ISupportView}
     */
    @Override
    public void onBindViewBefore() {

    }

    /**
     * 初始化视图之后的回调，详细解析在{@link ISupportView}
     */
    @Override
    public void onBindViewLater() {

    }

}
